#ifndef CTP_WRAPPER_LIBRARY_H
#define CTP_WRAPPER_LIBRARY_H

#if defined(_WIN32) || defined(__CYGWIN__)
    #ifdef MYLIB_EXPORTS
        #define MYLIB_API __declspec(dllexport)
    #else
        #define MYLIB_API __declspec(dllimport)
    #endif
#else
    #if __GNUC__ >= 4 || defined(__clang__)
        #define MYLIB_API __attribute__ ((visibility ("default")))
    #else
        #define MYLIB_API
    #endif
#endif

typedef char InstrumentCodeType[30];
struct CtpMarketRequest
{
    char url[16];          // IP地址：15字符+1终止符
    int port;              // 端口号
    InstrumentCodeType *instruments; // 指向10字符数组的指针（二维数组结构）
    int count;
    char flow_path[100];
};

struct CtpMarketResponse
{
    int success_inst_len;
    char shm_name[20];     // 共享内存名称
    char msg[100];         // 错误信息
};
typedef void* Handle;
typedef void* PVMarketData;


struct s;

struct MarketData {
    char symbol[32];       // 合约代码

    int volume_0d1;
    int volume_0d5;
    int volume_1d0;

    int interest_0d1;
    int interest_0d5;
    int interest_1d0;

    double price_0d1;
    double price_0d5;
    double price_1d0;

    double time_force;

    struct {
        int a;
        int b;
    } c;

    int (*p2)[];
    void *p1[];

};
typedef int (*p2)[];
typedef    void *p1[];
#ifdef __cplusplus
extern "C" {
#endif

    MYLIB_API Handle requestCtpMarket(struct CtpMarketRequest* request, struct CtpMarketResponse* response);
    MYLIB_API void stopCtpMarket(Handle handle);
    MYLIB_API void releaseCtpMarket(Handle handle);
    MYLIB_API void joinCtpMarket(Handle handle);
    MYLIB_API void queryCtpMarketSubIsSuccess(Handle handle);
    MYLIB_API void queryCtpMarketIsRunning(Handle handle);
    MYLIB_API PVMarketData queryCtpMarketData(Handle handle);
    MYLIB_API void queryCtpMarketQueueIsEmpty(Handle handle);
    MYLIB_API void ackCtpMarketData(Handle handle, PVMarketData);
    MYLIB_API void queryCtpQueueStatus(Handle handle, const int* enqueue, int* dequeue, int* fail_enqueue);
    MYLIB_API void getCTPVersion();

#ifdef __cplusplus
}
#endif

#endif //CTP_WRAPPER_LIBRARY_H